package com.dranie.validator;

import com.dranie.entity.Goods;
import com.jfinal.core.Controller;
import com.jfinal.upload.UploadFile;
import com.jfinal.validate.Validator;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

import java.io.File;
import java.util.Date;

/**
 * BlogValidator.
 */
public class GoodsValidator extends Validator {

    protected void validate(Controller controller) {
        validateRequiredString("goods.name", "nameMsg", "请输入商品名称!");
        validateRequiredString("goods.price", "priceMsg", "请输入商品单价!");
        validateRequiredString("goods.img", "imgMsg", "请上传商品图片!");
    }

    protected void handleError(Controller controller) {
        controller.keepModel(Goods.class);

        String actionKey = getActionKey();
        if (actionKey.equals("/admin/goods/save"))
            controller.render("add.html");
        else if (actionKey.equals("/admin/goods/update"))
            controller.render("edit.html");
    }
}
